<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s" %> 
<!DOCTYPE html>
<html>
<%@include file="/WEB-INF/base/commRoot.jsp"%>
  <head>
    <base href="<%=basePath%>">
    
    <title>惠卡宝定期计划</title>
	
   <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">

	<script type="text/javascript" src="/js/jquery-1.11.1.min.js"></script>
	<script type="text/javascript" src="/js/rsa/RSA.js"></script> 
	<script type="text/javascript" src="/js/rsa/BigInt.js"></script> 
	<script type="text/javascript" src="/js/rsa/Barrett.js"></script> 
	<script type="text/javascript" src="/js/rsa/RsaDataUtil.js"></script> 
	<script type="text/javascript" src="/js/win_layer/win_layer.js"></script>
	<script type="text/javascript" src="/js/view/account/sms.js"></script>
	<script type="text/javascript" src="/js/view/account/utils.js"></script>

	<style type="text/css">
	/* 修改购买定投转让样式 */
	.pop_take .tit {
		width: 140px !important;
	}

	</style>
  </head>
  
  <body>
 <input id="module" type="hidden" value="<s:property value='#application.module'/>">
<input id="empoent" type="hidden" value="<s:property value='#application.empoent'/>">
<!--header-->
	<jsp:include page="/head.jsp"></jsp:include>
<!--/header-->
<!--main-->
<div class="main_bg">        	
    <div class="hkb_plan_img position">
    	<h3>惠卡宝定期计划</h3>
    	<img src="/images/hkb_plan_img.gif" width="1018" height="253" alt="惠卡宝定期计划">
    </div>
     <!--tab-->
    <div class="take_tit">
        <ul id="tab" class="tab_tit_plan" style=" ">
        	<s:if test="tabType == 'hkb_plan_list' || tabType == null">
	            <li class="fli"><a href="javascript:switchTab('hkb_plan_list');">计划列表</a></li>
	            <li><a href="javascript:switchTab('transfer_list');">转让列表</a></li>
            </s:if>
            <s:else>
	            <li><a href="javascript:switchTab('hkb_plan_list');">计划列表</a></li>
	            <li class="fli"><a href="javascript:switchTab('transfer_list');">转让列表</a></li>
            </s:else>
        </ul>
    </div>
    <div id="tab_con">
	    <s:if test="tabType != 'transfer_list' || tabType == null">
	    	<div class="fdiv dis_no">
		    	<div class="hkb_plan_list">
				    <form action="<s:url value="/account/hkbProjectAipAction_findHkbProjectAll.action"/>" method="post" id="hkbProjectForm">
				    	<s:iterator var="projectDef"	value="#page.records">
					        <dl class="clearfix">
					        	<dt><s:property value="#projectDef.proTitle"/><span class="orange" style="font-size:15px; font-weight:normal; padding-left:20px;">每天计息，随时可转让变现</span></dt>
					            <dd class="yields">年化收益率：<span class="orange"><s:property value="%{annualYieldRate(#projectDef.profitRate)}"/></span><em class="orange">%</em></dd>
					            <dd class="income">每万元每日收益：<span class="profitRate"><s:property value="#projectDef.profitRate"/> </span>&nbsp;<em>元</em></dd>
					            <dd class="term">锁定期：<span><s:property value="#projectDef.termTime"/></span><em>&nbsp;<s:if test="#projectDef.termTimeType==1">天</s:if><s:elseif test="#projectDef.termTimeType==2">个月</s:elseif><s:elseif test="#projectDef.termTimeType==3">年</s:elseif></em></dd>
					            <dd class="ensure">保障方式：<span><s:property value="#projectDef.securityDiscrible"/></span></dd>
					            <dd class="go_btn">
					            <s:if test="#projectDef.switchStatus!=1">
					            	<a href="javascript:void(0);" style="background: #ccc;">已关闭</a>
					            </s:if>
					            <s:elseif test="#projectDef.restrictiousMinge != -1 && #projectDef.absorbMinge>=#projectDef.restrictiousMinge">
					            	<a href="javascript:void(0);" style="background: #ccc;">已满</a>
					            </s:elseif>
					            <s:else>
					            	<a href="javascript:void(0);" class="btn_pop">立即转入</a>
					            </s:else>
					            <input id="differDays" type="hidden" value="<s:property value="#projectDef.differDays"/>"/><input type="hidden" id="HkbProId" value="<s:property value="#projectDef.id"/>"/>	<input type="hidden" id="Amountmax" value="<s:property value="#projectDef.singleInvestRestrictionsAmountTop"/>"/><input type="hidden" id="AmountLow" value="<s:property value="#projectDef.singleInvestRestrictionsAmountLow"/>"/>	
					            </dd>
					        </dl>
				        </s:iterator>
				        	<script type="text/javascript">
				        			function changeTwoDecimal_f(x) {
									var f_x = parseFloat(x);
									if (isNaN(f_x)) {
									alert('function:changeTwoDecimal->parameter error');
									return false;
									}
									var f_x = Math.round(x * 100) / 100;
									var s_x = f_x.toString();
									var pos_decimal = s_x.indexOf('.');
									if (pos_decimal < 0) {
									pos_decimal = s_x.length;
									s_x += '.';
									}
									while (s_x.length <= pos_decimal + 2) {
									s_x += '0';
									}
									return s_x;
									}
				        	
					            	$(".profitRate").each(function(){
					            		var profitRate =$(this).html();
					             		$(this).html(parseFloat(profitRate*100).toFixed(2));
					            	})
					             	
					             </script>
				        	<%-- ><div class="clearfix">
				                <p class="page r">
										<%@include file="/WEB-INF/base/page.jsp"%>
										<input type="hidden" id="pageNo" name="pageNo" value="<s:property value="#page.currentPage"/>" />
									</p>
				                </div>--%>
				    </form>
			    </div>
			</div>
		</s:if>
		<s:else>
		     <!--转让列表-->
	        <div class="transfer_list">
	        	<form action="<s:url value="/account/hkbProjectAipAction_findHkbProjectAll.action"/>" method="post" id="hkbTransferForm">
	        	<input type="hidden" name="tabType" value="transfer_list" />
	        	<input type="hidden" name="hkbProId" id="transfer_list_hkbProId"/>
	        	<p class="selt">
	        	<s:if test="#hkbProjectDefList != null ">
	        		<s:if test="hkbProId == null || hkbProId == ''">
	        			<a href="javascript:pageInvestItermByProjectId('');" class="active">全部</a>
	        		</s:if>
	        		<s:else>
	        			<a href="javascript:pageInvestItermByProjectId('');">全部</a>
	        		</s:else>
		            <s:iterator value="#hkbProjectDefList" var="item">
			            <s:if test="hkbProId == #item.id">
			            	<s:if test="#item.termTimeType==1">
			              		<a href="javascript:pageInvestItermByProjectId('<s:property value="#item.id"/>');" class="active"><s:property value="#item.termTime"/>天定期</a>
			            	</s:if>
			            	<s:elseif test="#item.termTimeType==3">
			              		<a href="javascript:pageInvestItermByProjectId('<s:property value="#item.id"/>');" class="active"><s:property value="#item.termTime"/>年定期</a> 
			            	</s:elseif>
			            	<s:else>
			            		<a href="javascript:pageInvestItermByProjectId('<s:property value="#item.id"/>');" class="active"><s:property value="#item.termTime"/>月定期</a> 
			            	</s:else>
			            </s:if>
			            <s:else>
			            	<s:if test="#item.termTimeType==1">
				            	<a href="javascript:pageInvestItermByProjectId('<s:property value="#item.id"/>');"><s:property value="#item.termTime"/>天定期</a>
				            </s:if>
				            <s:elseif test="#item.termTimeType==3">
				            	<a href="javascript:pageInvestItermByProjectId('<s:property value="#item.id"/>');"><s:property value="#item.termTime"/>年定期</a>
				            </s:elseif>
				            <s:else>
				            	<a href="javascript:pageInvestItermByProjectId('<s:property value="#item.id"/>');"><s:property value="#item.termTime"/>月定期</a>
				            </s:else>
			            </s:else>
			            
		            </s:iterator>
	        	</s:if>
	        	</p>
	            <table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size: 13px;">
	            	<thead>
	                    <tr bgcolor="#eeeef4">
	                      <th width="114" height="50" align="left" class="td1">项目名称</th>
	                      <th width="150">用户名</th>
	                      <th width="100" align="center">转让本金(元)</th>
	                      <th width="100" align="center">转让价(元)</th>
	                      <th width="95">年化收益率</th>
	                      <th width="104">剩余锁定期</th>
	                      <th width="130">转让申请有效时间</th>
	                      <th width="122">预计收益(元)</th>
	                      <th width="95">&nbsp;</th>
	                    </tr>
	                </thead>
	                <tbody>
	                <s:if test="#page.totalRecord > 0">
	                 	<s:iterator value="#page.records" var="item" status="st">
	                 		<s:if test="#st.Even">
		                 	<tr bgcolor="#c7c7c7" height="44">
		                 	</s:if>
		                 	<s:else>
		                 	<tr height="44">
		                 	</s:else>
		                 	<%-- <td class="td1"	title="<s:property value="#item.hkbProjectDef.proTitle"/>"><s:if
										test="%{null!=#item.hkbProjectDef.proTitle&&#item.hkbProjectDef.proTitle.length()>7}">
										<s:property value="%{#item.hkbProjectDef.proTitle.substring(0, 7)}" />...
					        </s:if> <s:else>
										<s:property value="#item.hkbProjectDef.proTitle" />
									</s:else>&nbsp;</td> --%>
		                 		<%-- <td class="td1"><s:property value="#item.hkbProjectDef.proTitle"/></td> --%>
		                 		<td class="td1"	title="<s:property value="#item.proTitleName"/>"><s:if
										test="%{null!=#item.proTitleName&&#item.proTitleName.length()>7}">
										<s:property value="%{#item.proTitleName.substring(0, 7)}" />...
					       				</s:if> <s:else>
										<s:property value="#item.proTitleName" />
									</s:else>&nbsp;</td>
			                    <td align="center"><s:property value="#item.accName"/></td>
			                    <td align="center"><s:property value="%{formatMoney(#item.investAmount)}"/></td>
			                    <td align="center"><s:property value="%{formatMoney(#item.bargainReceiptPrice)}"/></td>
			                    <td align="center"><s:property value="%{annualYieldRate(#item.hkbProjectDef.profitRate)}"/>%</td>
			                    <td align="center"><s:property value="#item.surplusDays"/>天</td>
			                    <td align="center"><s:property value="#item.surplusTranfApplayDays"/></td>
			                    <td align="center"><s:property value="%{formatMoney(#item.expectedProfit)}"/></td>
			                    <td align="center">
			                    	<s:if test="#item.surplusTranfApplayDays != '已过期'">
			                    		<a href="javascript:takeOver(<s:property value="#item.id"/>);" class="btn_take">购买</a>
			                    	</s:if>
			                    	<s:else>
			                    		<a href="javascript:void(0);" class="btn_take" style="background: #ccc;border: 1px solid #ccc;">已过期</a>
			                    	</s:else>
			                    </td>
			                </tr>
	                 	</s:iterator>
	                 </s:if>
	                 <s:else>
	                    <tr>
	                        <td height="40" align="center"  colspan="9">没有数据!</td>
	                    </tr>
	                 </s:else>
	                </tbody>
	            </table>
				<div class="clearfix">
			        <p class="page r">
					<%@include file="/WEB-INF/base/page.jsp"%>
					<input type="hidden" id="pageNo" name="pageNo" value="<s:property value="#page.currentPage"/>" />
					</p>
			    </div>  
			   </form>      
			</div>
	        <!--/转让列表-->
	    </s:else>
    </div>
    <div class="hkb_plan_descri">
   	  <h3>计划介绍</h3>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:18px;">
          <tr bgcolor="#bababa" height="45" style="color:#fff;">
            <td width="18%" align="right" class="td1">名　称</td>
            <td width="82%">惠卡宝定期计划</td>
          </tr>
          <tr bgcolor="#ededed" height="90">
            <td align="right" class="td1">计划介绍</td>
            <td>惠卡宝定期计划是惠卡贷推出的优质借款标集合投标计划，用户加入定期计划后，按照约定的锁定期限，坐享收益。安全，方便，收益高。</td>
          </tr>
          <tr bgcolor="#bababa" height="45" style="color:#fff;">
            <td align="right" class="td1">锁定期</td>
            <td>3-36个月</td>
          </tr>
          <tr bgcolor="#ededed" height="45">
            <td align="right" class="td1">收益处理方式</td>
            <td>每天转入惠信钱包</td>
          </tr>
          <tr bgcolor="#bababa" height="45" style="color:#fff;">
            <td align="right" class="td1">本金处理方式</td>
            <td>到期后自动转入惠信钱包</td>
          </tr>
          <tr bgcolor="#ededed" height="45">
            <td align="right" class="td1">本息保障方式</td>
            <td>100%保本保息</td>
          </tr>
        </table>

    </div>


</div>
<!--/main-->
<!--footer-->
<jsp:include page="/footer.jsp"></jsp:include>


<!--popup-->

<div id="joinHkb" class="popup dis_no"  style=" width:500px; margin-left:-245px;" onMouseDown="moveEvent(event,this.id)">
	<h3><span>参加惠卡宝定期计划</span><a href="javascript:void(0);" class="close"></a></h3>
	<input type="hidden" id="spanHkbProId" name="spanHkbProId"/>
	<input type="hidden" id="ejectDifferDays" value=""/>
    <ul class="pop_hkb_plan">
    	<li class="clearfix li_text"><label class="tit">账户余额：</label><span class="orange l" id="spanMoney">元</span>  <a href="<s:url value="/fundRecord_recharge.action"/>" class="blue r">立即充值</a></li>
        <li class="clearfix li_text pop_padd0"><label class="tit">年化收益率：</label><span class="orange l" id="spanRecord"></span><span class="r" id="spanTermTime"></span></li>
        <li class="clearfix" style="height:58px;"><label class="tit">转入金额：</label><div class="l"><div class="clearfix"><input name="hkbProjectDefMoney" onkeyup="rcalculate2(this.value)" maxlength="16" type="text" class="input l" id="hkbProjectDefMoney"  onblur="blurCheck(1)" onfocus="focusCheck('moneyCheck')"><p class="tips  l v"  style="line-height: 18px;"><b  id="AmountDown">0</b>元起投<br/><b id="AmountTop">0</b><em id="nextAmountTop">元封顶</em></p></div>
        	<p id="moneyCheck" style="width:260px;"></p></div></li>
        <li class="clearfix" style="height:68px; padding-top:8px;"><label class="tit">支付密码：</label><div class="l"><input name="payPwd" type="password" class="input" id="payPwd"  onblur="blurCheck(2)" onpaste="return false"  onfocus="focusCheck('pwdCheck')">
        	<p  id="pwdCheck" style="width:260px;"></p></div></li>
        <li class="clearfix li_text pop_padd0"><label class="tit">预计每日收益：</label><span class="orange l" id="preProfit">0</span>元</li>
        <li class="clearfix li_text pop_padd0"><label class="tit">预计总收益：</label><span class="orange l" id="preProfitCount">0</span>元</li>
        <li class="clearfix agree"><input name="agreement"  checked="checked" type="checkbox" value="" class="l mar_li" id="agreeAip" style="margin-left:130px;"><label for="agree">我已阅读并同意<a href="${root}/staticAction_hkbRegularAgreement.action" target="_blank" class="blue">《惠卡宝定期计划服务协议》</a></label></li>
    </ul>
    <div class="popup_bottom"><a href="javascript:commitHkbProject();" class="btn" id="aipCommit">立即转入</a></div>
</div>
<div class="pop_up_bg dis_no"></div>


<!--popup-->

<div id="buyHkb" class="popup_take dis_no" style=" width:500px; margin-left:-245px; top: 5%;"  onMouseDown="moveEvent(event,this.id)">
	<h3><span>购买惠卡宝定期计划</span><a href="javascript:void(0);" class="close" id="popup_take_close"></a></h3>
	<input type="hidden" id="hkbInvestItermID" name="hkbInvestItermID"/>
    <ul class="pop_take">
    	<li class="clearfix li_text"><label class="tit">账户余额：</label><span class="orange l" id="accountCash"></span>  <a href="javascript:to_recharge('recharge')" class="blue r">立即充值</a></li>
        <li class="clearfix li_text"><label class="tit">订单编号：</label><span id="orderNo"></span> </li>
        <li class="clearfix li_text"><label class="tit">年化收益率：</label><span class="orange l" id="profitRate"></span></li>
        <li class="clearfix li_text pop_padd0"><label class="tit">剩余锁定期：</label><span class="l" id="surplusDays"></span><span style="float:right;">锁定期内只可转让定期计划</span></li>
        <li class="clearfix li_text pop_padd0"><label class="tit">转让申请有效时间：</label><span class="l" id="surplusTranfApplayDays"></span></li>
        <li class="clearfix li_text"><label class="tit">买入金额：</label><span class="l" id="investAmount"></span></li>
        <li class="clearfix li_text"><label class="tit">买入价：</label><span class="orange l" id="bargainReceiptPrice"></span></li>
        <li class="clearfix li_text"><label class="tit">预计收益：</label><span class="l" id="expectedProfit"></span></li>
        <li class="clearfix" style="height:68px; padding-top:8px;">
        	<label class="tit">支付密码：</label>
        	<div class="l">
        		<input type="password" placeholder="输入支付密码" id="payPsw" onBlur="checkpassword(this.value)" onfocus="removeAt();" onblur="removeEvent();" name="" class="input" onpaste="return false"/>
        		<p class="err_tips"></p>
        	</div>
        </li>
        <li class="clearfix agree"><input name="agreement"  checked="checked" type="checkbox" value="" class="l mar_li" id="transfAgreeAip" style="margin-left:140px;width:auto;"><label for="agree">我已阅读并同意<a href="${root}/staticAction_hkbRegularAgreement.action" target="_blank" class="blue">《惠卡宝定期计划服务协议》</a></label></li>
    </ul>
    <div class="popup_bottom"><a href="javascript:surerecharge_Sub();" id="buyhkb" class="btn">立即购买</a></div>
</div>
<div class="pop_up_bg_take dis_no"></div>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript">
$(function(){
	$("#agreeAip").click(function(){
		if($(this).is(':checked')){
			$("#aipCommit").css("background","none repeat scroll 0 0 #f40");
			$("#aipCommit").attr("href","javascript:commitHkbProject();");
		}else{
			$("#aipCommit").css("background","none repeat scroll 0 0 gray");
			$("#aipCommit").removeAttr("href");
		}
	});
	$("#transfAgreeAip").click(function(){
		if($(this).is(':checked')){
			$(".popup_bottom").find("#buyhkb").css("background","none repeat scroll 0 0 #f40");
			$(".popup_bottom").find("#buyhkb").attr("href","javascript:surerecharge_Sub();");
		}else{
			$(".popup_bottom").find("#buyhkb").css("background","none repeat scroll 0 0 gray");
			$(".popup_bottom").find("#buyhkb").removeAttr("href");
		}
	});
})

function userInfoCheck(){
	var flag = true;
	var beforStr="投资惠卡宝定期计划，需要先进行实名认证，手机绑定，支付密码设置。您的";
	var afterStr="未设置。单击确定到用户安全中心进行设置。";
	var i=0;
	if('<s:property value="#session.User_session_info.idcard"/>'=="" || '<s:property value="#session.User_session_info.realName"/>'==""){
		if(i==0){
			beforStr+="实名";
		}else{
			beforStr+="，实名";
		}
		i++;
		flag=false;
	}
	if('<s:property value="#session.User_session_info.mobile"/>'==""){
		if(i==0){
			beforStr+="手机";
		}else{
			beforStr+="，手机";
		}
		i++;
		flag=false;
	}
	if('<s:property value="#session.User_session_info.payPwd"/>'==""){
		if(i==0){
			beforStr+="支付密码";
		}else{
			beforStr+="，支付密码";
		}
		i++;
		flag=false;
	}
	if(!flag){
		layer.alert(beforStr+afterStr,8,function(){
			window.location='<s:url value="/account/safeAction_safe.action"/>';
		});
		
	}
	return flag;
}

$(function(){
	$("#hkbProjectDefMoney").val("");
	$("#payPwd").val("");
	
	$('.btn_pop').on('click', function(){
		var flag = userInfoCheck();
		if(flag){
			$.ajax({
	             type: "POST",
	             url:'<s:url value="/account/hkbProjectAipAction_findByUserFunds.action"/>',
	             dataType: "json",
	           	 success: function(data){
	           		 if((data.cash+"").indexOf(".") >-1){
	           			 $("#spanMoney").html(subNumber(data.cash,2)+"元");
	           		 }else{
	           			 $("#spanMoney").html(data.cash.toFixed(2)+"元");
	           		 }
		           	
	             }
        	});
				$("#ejectDifferDays").val($(this).siblings("#differDays").val());
				 $("#spanRecord").html($(this).parent().siblings(".yields").children("span").html()+"%");
				// $("#spanTermTime").html("锁定期："+$(this).parent().siblings(".term").children("span").html()+"个月");
				 $("#spanTermTime").html($(this).parent().siblings(".term").html());
				  $("#spanHkbProId").val($(this).siblings("#HkbProId").val());
				 if($(this).siblings("#AmountLow").val()==null || $(this).siblings("#AmountLow").val()=="" || $(this).siblings("#AmountLow").val()<=0) {
				 	$("#AmountDown").html(parseFloat(1).toFixed(2));
				 }else{
				 	$("#AmountDown").html(parseFloat($(this).siblings("#AmountLow").val()).toFixed(2));
				 }
				  if($(this).siblings("#Amountmax").val()==null || $(this).siblings("#Amountmax").val()=="" || $(this).siblings("#Amountmax").val()<=0){
				 	$("#AmountTop").html("");
				 	$("#nextAmountTop").html("");
				 }else{
				 	$("#AmountTop").html(parseFloat($(this).siblings("#Amountmax").val()).toFixed(2));
				 	$("#nextAmountTop").html("元封顶");
				 }
				 $('.popup').show();
				 $('.pop_up_bg').show();
		}
		
	});
	
    $('.close').on('click', function(){
	    $("#hkbProjectDefMoney").val("");
		$("#payPwd").val("");
		$("#moneyCheck").removeAttr("class").html("");
		$("#pwdCheck").removeAttr("class").html("");
		$("#preProfit").html("0");
		$("#preProfitCount").html("0");
		$('.popup').hide();
		$('.pop_up_bg').hide();
	});
    
    $('#popup_take_close').on('click', function(){
    	closeByHKBDiv();
	});
	
});

function focusCheck(obj){
	$("#buyHkb").removeAttr("onMouseDown");
	$("#joinHkb").removeAttr("onMouseDown");
	$("#"+obj).removeAttr("class").html("");
}

function rcalculate2(amount) {
	if (isNaN(Number(amount))) {
		$("#moneyCheck").removeAttr("class").attr("class","err_tips").html("充值金额格式错误");
		$("#preProfit").html(0);
		$("#preProfitCount").html(0);
		return false;
	}
	// 只能输入小数点后两位
	var indexOfPoint = amount.indexOf('.');
	var t1 = amount.substring(0, 1);
	var t2 = amount.substring(1, 2);
	if (indexOfPoint != -1) { 
		if (amount.length > indexOfPoint + 3) {
			$("#hkbProjectDefMoney").val(amount.substring(0, indexOfPoint + 3));
		}
	}if ((t1 == 0 && t2 == 0 && t2 != '')//不能输入类似金额00012
		|| (t1 == 0 && t2 != 0 && t2 != '.')) {
	     $("#hkbProjectDefMoney").val('');
	}if (Number(amount) < 1) {
		$("#amountMsg").removeAttr("class").attr("class","err_tips").html("充值金额不能小于1元");
		$("#preProfit").html(0);
		$("#preProfitCount").html(0);
		return false;
	}
}

function blurCheck(i){
	removeEvent();
	var hkbProjectDefMoney = $("#hkbProjectDefMoney").val().replace(/\s/g, "");
	var spanRecord =$("#spanRecord").html().replace("%", "").replace(/\s/g, "");
	var ejectDifferDays = $("#ejectDifferDays").val().replace(/\s/g, "");
	var re = /^([1-9]\d*|0)(?:\.\d{1,2})?$/; 
	///^[1-9]+[0-9]*]*$/;
	var AmountDown = $("#AmountDown").html();
	if(AmountDown!=null && AmountDown!=""){
		AmountDown=parseFloat(AmountDown);
	}else{
		AmountDown=parseFloat(0);
	}
	var AmountTop = $("#AmountTop").html();
	if(AmountTop!=null && AmountTop!=""){
		AmountTop=parseFloat(AmountTop);
	}else{
		AmountTop=parseFloat(0);
	}
	var flag =true; 
	if(i==1 || i>10){
		if(hkbProjectDefMoney==null || hkbProjectDefMoney==""){
		$("#moneyCheck").removeAttr("class").attr("class","err_tips").html("转入金额不能为空");
		$("#preProfit").html(0);
		$("#preProfitCount").html(0);
		flag=false;
		}else if(AmountDown>parseFloat(hkbProjectDefMoney)){
			$("#moneyCheck").removeAttr("class").attr("class","err_tips").html("金额必需大于或等于用户最低起投金额");
			$("#preProfit").html(0);
			$("#preProfitCount").html(0);
			flag=false;
		}else if(AmountTop<parseFloat(hkbProjectDefMoney) && AmountTop > 0){
			$("#moneyCheck").removeAttr("class").attr("class","err_tips").html("金额超出用户最高投注金额");
			$("#preProfit").html(0);
			$("#preProfitCount").html(0);
			flag=false;
		}else if(!re.test(hkbProjectDefMoney)){
			$("#moneyCheck").removeAttr("class").attr("class","err_tips").html("输入金额错误");
			$("#preProfit").html(0);
			$("#preProfitCount").html(0);
			flag=false;
		}else{
			$("#moneyCheck").removeAttr("class").html("");
			$("#preProfit").html((spanRecord/360/100*hkbProjectDefMoney).toFixed(2));
			$("#preProfitCount").html((spanRecord/360/100*hkbProjectDefMoney*(ejectDifferDays-1)).toFixed(2));
		}
	}
	if(i==2 || i>10){
		var payPwd = $("#payPwd").val();
		if(payPwd==null || payPwd==""){
			$("#pwdCheck").removeAttr("class").attr("class","err_tips").html("支付密码不能为空");
			flag=false;
		}else if(payPwd.length<8 || payPwd.length>16){
			$("#pwdCheck").removeAttr("class").attr("class","err_tips").html("支付密码必须8到16位");
			flag=false;
		}else{
			$("#pwdCheck").removeAttr("class").html("");
		}
	}
	return flag;
}
function commitHkbProject(){
		var hkbProjectDefMoney = $("#hkbProjectDefMoney").val().replace(/\s/g, "");
		var payPwd = $("#payPwd").val();
		payPwd=rsaData(payPwd);
		var flag= blurCheck(11);
		if(flag){
			if (this.ajaxRequest_ != undefined && this.ajaxRequest_.readyState < 4) {
	                    return;
	         }else{
	         	this.ajaxRequest_=$.ajax({
		             type: "POST",
		             url:'<s:url value="/account/hkbProjectAipAction_saveUserHkbProjectDef.action"/>',
		             data: {hkbProId:$("#spanHkbProId").val(),hkbProjectDefMoney:hkbProjectDefMoney,payPwd:payPwd},
		             dataType: "json",
		           	 success: function(data){
		           	 	var msg= data.msg;
		           	 	if(msg=="error"){
		           	 		layer.alert("操作失败!",8);
		           	 		$('.close').click();
		           	 	}else if(msg=="success"){
		           	 		layer.alert("操作成功!",9);
		           	 		$('.close').click();
		           	 	}else if(msg=="unsettedPwd"){
		           	 		layer.alert("未设置支付密码，单击确定到用户安全中心进行设置",8,function(){
		           	 			window.location='<s:url value="/account/safeAction_safe.action"/>';
		           	 		})
		           	 		
		           	 		return;
		           	 	}else{
		           	 		layer.alert(msg,8);
		           	 		return;
		           	 	}
		             }
	        	});
	         }
			
		}
			
}
// 切换计划列表、转让列表
function switchTab(tabType){
	window.location.href='<s:url value="/account/hkbProjectAipAction_findHkbProjectAll.action?tabType="/>'+tabType;
}
// 转让列表查询
function pageInvestItermByProjectId(proId){
	$("#transfer_list_hkbProId").val(proId);
	$("#hkbTransferForm").submit();
	
}

function closeByHKBDiv(){
	$(".popup_take .pop_take").find(".err_tips").html('');
	$('.popup_take').hide();
	$('.pop_up_bg_take').hide();
}
// 获取转让数据及渲染页面
function takeOver(id){

	var flag = userInfoCheck();
	if(flag){
		$.ajax({
	        type: "POST",
	        url:'<s:url value="/account/hkbProjectAipAction_findHkbInvestIterm.action"/>',
	        data: {hkbInvestId:id},
	        dataType: "json",
	      	success: function(data){
	      		if(data && data.length>0 && data[0].userFunds){
	      			var result = data[0];
	          	 	var $popTake = $(".pop_take");
	          	 	var $popupTake = $(".popup_take");
	          	 	$popTake.find(".suc_tips").html('');// 清空提示信息
	          	 	$popTake.find("#payPsw").val("");// 清空支付密码
	          	 	$popupTake.find("#hkbInvestItermID").val(result.hkbInvestIterm.id);
	          		$popTake.find("#accountCash").text(interceptDecimal(result.userFunds.cash)+"元");//账户余额
	          	 	$popTake.find("#orderNo").text(result.hkbInvestIterm.orderNo);// 订单编号
	          	 	$popTake.find("#profitRate").text((parseInt(result.daysInYear)*parseFloat(result.hkbInvestIterm.hkbProjectDef.profitRate)).toFixed(2)+"%");// 年收益率:日收益率转为年收益率
	          	 	$popTake.find("#surplusDays").text(result.hkbInvestIterm.surplusDays+"天");// 剩余锁定期
	          	 	$popTake.find("#surplusTranfApplayDays").text(result.hkbInvestIterm.surplusTranfApplayDays);// 转让申请有效时间
	          	 	$popTake.find("#bargainReceiptPrice").text(interceptDecimal(result.hkbInvestIterm.bargainReceiptPrice)+"元");// 买入价
	          	 	$popTake.find("#expectedProfit").text(interceptDecimal(result.hkbInvestIterm.expectedProfit)+"元");// 预计收益
	          	 	$popTake.find("#investAmount").text(interceptDecimal(result.hkbInvestIterm.investAmount)+"元");// 买入金额
	          	 	$('.popup_take').show();
	        		$('.pop_up_bg_take').show();
	      		}else if(data && data.length>0){
	      			if(data[0] == 1){
	      				layer.alert("购买惠卡宝定期计划，需要先进行手机认证，实名认证，单击确定到用户安全中心进行认证!",8,function(){
	      					redirectSafeAction();
	      				});
	      				
	    			}else if(data[0] == 2){
	    				layer.alert("资金不足，无法购买。点击确定进行充值!",8,function(){
	    					to_recharge('recharge');
	      				});
	    			}else if(data[0] == 3){
	    				layer.alert("该定投转让已过期!",8,function(){
	    					$("#hkbTransferForm").submit();
	      				});
	    			}
	      		}else{
	      			layer.alert("系统忙，请稍后重试",8);
	      		}
	        }
		}); 
	}
	 
}

//输入验证自动验证
function checkpassword(payPsw) {
	$("#buyHkb").removeAttr("onMouseDown");
	$("#joinHkb").removeAttr("onMouseDown");
	if (payPsw == "" || trim(payPsw) == "" || trim(payPsw).length == 0) {
		$(".pop_take").find(".err_tips").html("请输入支付密码");
		return false;
	} else if (trim(payPsw).length < 8 || trim(payPsw).length > 16) {
		$(".pop_take").find(".err_tips").html("支付密码输入不正确");
		return false;
	}
	$(".pop_take").find(".err_tips").html('');
	return true;
}

function removeAt(){
	$(".pop_take").find(".err_tips").html("");
}

function trim(str) { // 删除左右两端的空格
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

//确定接手
function surerecharge_Sub() {
	var hkbInvestId = $(".popup_take").find("#hkbInvestItermID").val();
	var $payPsw = $(".pop_take").find("#payPsw");
	if(!checkpassword($payPsw.val())){
		//$payPsw.focus();
		return;
	}
	var payPwd = rsaData($payPsw.val());
	$.ajax({
		type : "POST",
		url:'<s:url value="/account/hkbProjectAipAction_takeOver.action"/>',
		data : {hkbInvestId:hkbInvestId,payPsw:payPwd},
		dataType : 'text',
		success : function(data) {
			if(data == "1"){
				$(".pop_take").find(".err_tips").html('请先进行手机认证，实名认证');
			}else if(data == "2"){
				$(".pop_take").find(".err_tips").html('请输入支付密码');
			}else if(data == "3"){
				$(".pop_take").find(".err_tips").html('支付密码错误');
			}else if(data == "success"){
				$(".pop_take").find(".err_tips").html('');
				closeByHKBDiv();
				layer.alert("购买成功",9,function(){
					switchTab('transfer_list')
					//window.location.href='<s:url value="/account/hkbProjectAipAction_findHkbProjectAll.action?tabType=transfer_list"/>';
  				});
			}else if(data == "cashError"){
				$(".pop_take").find(".err_tips").html('账户资金不足，请充值');
			}else if(data == "dataError")
			{
				$(".pop_take").find(".err_tips").html('请求数据异常');
			}else{
				$(".pop_take").find(".err_tips").html('系统忙，请稍后重试');
			}
		}
	});
}
// 充值
function to_recharge(to_str){
	 location.href=ctx_root+"/fundRecord_"+to_str+".action";
}
// 跳转至安全中心页面
function redirectSafeAction(){
	window.location='<s:url value="/account/safeAction_safe.action"/>';
}
</script>
</body>
</html>
